﻿using MMCInfo.Models;
using MMCInfo.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;

namespace MMCInfo.Controllers
{
    public class DeveloperController : Controller
    {
        //
        // GET: /Developer/

        [Authorize(Roles = "Developer")]
        public ActionResult Index()
        {
            return View();
        }

        //
        // GET: /Account/Register
        [Authorize(Roles = "Developer")]
        public ActionResult CreateAccount()
        {
            Entities db = new Entities();

            CreateUserModel model = new CreateUserModel();

            return View(model);
        }

        //
        // POST: /Account/Register
        [Authorize(Roles = "Developer")]
        [HttpPost]
        public ActionResult CreateAccount(CreateUserModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                MembershipCreateStatus createStatus;
                Membership.CreateUser(model.UserName, model.UserName, model.Email, null, null, true, null, out createStatus);

                if (createStatus == MembershipCreateStatus.Success)
                {
                    // Rol zetten voor deze nieuwe gebruiker
                    Roles.AddUserToRole(model.UserName, model.Role);
                    return RedirectToAction("CreateAccount", "Developer");
                }
                else
                {
                    //ModelState.AddModelError("", ErrorCodeToString(createStatus));
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }

    }
}
